<?php
class koudai_order_cartModel extends model{
	public $base;
	public $oc_where;
	public function __construct(&$base){
		parent::__construct($base);
		$this->base=$base;
		$this->table="koudai_order_cart";
		$this->oc_where=M('login')->userid?" (userid=".M('login')->userid." or oc_ssid='".OC_SSID."') ":"oc_ssid='".OC_SSID."' ";
		$this->oc_where.=" AND siteid=".SITEID;
	}
	
	
	public function getListByUser($w=''){
		$option=array(
			"where"=>$this->oc_where.$w
		);
		$data=$this->select($option);
		$total_money=0;
		$total_num=0;
		if($data){
			foreach($data as $v){
				
				$ids[]=$v['productid'];
				$cart[$v['object_id']]=$v;
			}
		 	$products=M("product")->getListByIds($ids);
			foreach($data as $v){
				$total_money +=$v['amount']*$products[$v['productid']]['price'];
				$total_num+=$v['amount'];
			}
			return array("product"=>$cart,"total_money"=>$total_money,"total_num"=>$total_num);
		}
	}
	
	 
	
	
	
	
}

?>